package com.zw.stock_sell_storage.controller;

import com.zw.stock_sell_storage.dto.SaleCarDto;
import com.zw.stock_sell_storage.dto.SaleInformationDto;
import com.zw.stock_sell_storage.dto.ex.UserDtoEx;
import com.zw.stock_sell_storage.service.ISaleCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/saleCar")
public class SaleCarController {

    @Autowired
    ISaleCarService iSaleCarService;

    @RequestMapping("/querySaleCarList")
    public List<SaleCarDto> querySaleCarList(HttpServletRequest request){
        UserDtoEx userDtoEx = (UserDtoEx) request.getSession().getAttribute("user");
        return iSaleCarService.querySaleCarList(userDtoEx.getUserId());
    }

    @RequestMapping("/addSaleCar")
    public boolean addSaleCar(@RequestBody SaleCarDto saleCarDto,HttpServletRequest request){
        UserDtoEx userDtoEx = (UserDtoEx) request.getSession().getAttribute("user");
        saleCarDto.setFkUserId(userDtoEx.getUserId());
        return iSaleCarService.addSaleCar(saleCarDto);
    }

    @RequestMapping("/updateSaleCar")
    public boolean updateSaleCar(@RequestBody SaleCarDto saleCarDto){
        return iSaleCarService.updateSaleCar(saleCarDto);
    }

    @RequestMapping("/rmvSaleCarById")
    public boolean rmvSaleCarById(int saleCarId){
        return iSaleCarService.rmvSaleCarById(saleCarId);
    }

    @RequestMapping("/rmvAllSaleCar")
    public boolean rmvAllSaleCar(int userId){
        return iSaleCarService.rmvAllSaleCar(userId);
    }

    @RequestMapping("/pushSaleCar")
    public boolean pushSaleCar(@RequestBody SaleInformationDto saleInformationDto, HttpServletRequest request){
        UserDtoEx userDtoEx = (UserDtoEx) request.getSession().getAttribute("user");
        return iSaleCarService.pushSaleCar(saleInformationDto,userDtoEx.getUserId());
    }
}
